#include <iostream>
#include <string.h>
using namespace std;

//length为牛客系统规定字符串输出的最大长度，固定为一个常数
class Solution {
public:
	void replaceSpace(char *str,int length) {
		if(str == nullptr || length <= 0)
			return;
		int strlth = 0,space = 0;
		while(str[strlth]){
			if(str[strlth] == ' ')
				++space;
			++strlth;
		}
		cout<<strlth << " , "<<space<<endl;
		for(int i = strlth + space*2 ; i >= 0 ; --i,--strlth)
		{
			if(str[strlth] == ' ')
			{
				str[i] = '0';
				str[i-1] = '2';
				str[i-2] = '%';
				i-=2;
			}
			else
				str[i] = str[strlth];
		}
	}
};

int main()
{
	Solution s;

	char str[40];
	strcpy(str,"  haha ");
	s.replaceSpace(str,40);
	cout<<str<<endl;
}